package com.fulong.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


import com.fulong.entity.DeviceBaiseInfoEntity;

import com.fulong.service.DeviceBaiseInfoService;
import com.fulong.web.webconfig.UserStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.fulong.common.utils.PageUtils;
import com.fulong.common.utils.R;



/**
 * 
 *
 * @author fulong
 * @email ${email}
 * @date 2022-02-25 18:53:09
 */
@RestController
@RequestMapping("/devicebaiseinfo")
public class DeviceBaiseInfoController {
    @Autowired
    private DeviceBaiseInfoService deviceBaiseInfoService;
    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = deviceBaiseInfoService.queryPage(params);
        return R.ok().put("page", page);
    }


    /*
    * 设备树形结构
    * */
    @RequestMapping("/devicelist")
    public R devicelist(){
        List<DeviceBaiseInfoEntity> deviceBaiseInfoEntities = deviceBaiseInfoService.listWithTree();
        String id = UserStatus.getParam().getId();
        return R.ok().put("data", deviceBaiseInfoEntities).put("userid" , id);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") String id){
		DeviceBaiseInfoEntity deviceBaiseInfo = deviceBaiseInfoService.getById(id);

        return R.ok().put("deviceBaiseInfo", deviceBaiseInfo);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody DeviceBaiseInfoEntity deviceBaiseInfo){
		deviceBaiseInfoService.save(deviceBaiseInfo);
        return R.ok().put("id" , deviceBaiseInfo.getId());
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody DeviceBaiseInfoEntity deviceBaiseInfo){
		deviceBaiseInfoService.updateById(deviceBaiseInfo);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody String[] ids){
		deviceBaiseInfoService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
